import java.util.Stack;

public class MinStack {

    private Stack<Integer> stack ;
    private Stack<Integer> minStack ;

    public MinStack() {
        this.stack = new Stack<>();
        this.minStack = new Stack<>();
    }
    
    public void push(int val) {
        stack.push(val);
        if(minStack.empty()) {
            minStack.push(val);
        }else {
            int x = minStack.peek();
            //这个等号必须得取
            if(x >= val) {
                minStack.push(val);
            }
        }
    }
    
    public void pop() {
        if(stack.empty()) {
            return;
        }
        int x = stack.pop();
        //每次弹出元素的时候，都需要和最小栈的栈顶元素比较的
        if(x == minStack.peek()) {
            minStack.pop();
        }
    }

    /**
     * 只是获取普通的栈的栈顶元素
     * @return
     */
    public int top() {
        if(stack.empty()) {
            return -1;
        }
        return stack.peek();
    }

    /**
     * 获取当前栈的最小元素
     * @return
     */
    public int getMin() {
        if(minStack.empty()) {
            return -1;
        }
        return minStack.peek();
    }
}